package com.mark.web.sys.controller.backend;

import com.github.pagehelper.PageInfo;
import com.mark.common.ServerResponse;

import com.mark.web.sys.entity.vo.UserVo;
import com.mark.web.sys.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 用户名模块后台控制器
 * @Author: Mark
 * @CreateDate: 2018/8/14.
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@Api(value = "管理员-用户模块")
@RestController
@RequestMapping(value = "/manage/user/")
public class UserManageController {

    private final IUserService iUserService;

    @Autowired
    public UserManageController(IUserService iUserService) {
        this.iUserService = iUserService;
    }

    /**
     * 1.获取用户列表
     * @param pageNum :页数
     * @param pageSize ： 页面大小
     * @return 用户列表
     */
    @ApiOperation(value = "获取用户列表",notes = "")
    @PostMapping(value = "list.do")
    public ServerResponse<PageInfo<UserVo>> getUserList(@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                                        @RequestParam(value = "pageSize", defaultValue = "10") int pageSize){
        PageInfo<UserVo> model =  iUserService.getUserList(pageNum,pageSize);
        return ServerResponse.model(model);
    }

    //2.用户的状态的改变：正常用户<--->拉黑用户
    @PostMapping(value = "update_user_status.do")
    public ServerResponse setUserEnableStatus(Integer userId,Integer newStatus,String remark){
        return iUserService.setUserEnableStatus(userId,newStatus,remark);
    }

    //3.搜索用户信息（姓名模糊查询，ID，状态）
    @PostMapping(value = "search_users.do")
    public  ServerResponse searchUsers(@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                       @RequestParam(value = "pageSize",defaultValue = "10") int pageSize,
                                       String userName,Integer userId ,Integer status){
        return iUserService.searchUsers(pageNum,pageSize,userName,userId,status);
    }


    

}
